<template>
    <div class="equipment-container">
        <el-card>
            <el-card class="header">
                <el-form ref="form" :model="form" label-width="80px">
                    <el-form-item label="器材名称">
                        <el-input v-model="form.equipmentName" placeholder="请输入器材名称" class="query"></el-input>
                    </el-form-item>
                    <el-button type="primary" @click="getList">查询</el-button>
                </el-form>
            </el-card>
            <el-table :data="tableData" border style="width: 100%">
                <el-table-column prop="equipmentName" label="器材名称" width="180"></el-table-column>
                <el-table-column prop="equipmentLocation" label="器材位置" width="180"></el-table-column>
                <el-table-column prop="equipmentStatus" label="器材状态" width="180"></el-table-column>
                <el-table-column prop="equipmentMessage" label="备注信息"></el-table-column>
            </el-table>
            <div class="pagination">
                <el-pagination :current-page="currentPage" :page-sizes="[10, 30, 60, 90]" :page-size="pageSize" :total="total"
                    @size-change="handleSizeChange" @current-change="handleCurrentChange"
                    layout="total, sizes, prev, pager, next, jumper">
                </el-pagination>
            </div>
        </el-card>
        <el-dialog title="提示" :visible.sync="dialogVisible" :before-close="handleClose">
            <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
                <el-form-item label="器材名称" prop="equipment_name">
                    <el-input v-model="ruleForm.equipment_name"></el-input>
                </el-form-item>
                <el-form-item label="器材位置" prop="equipment_location">
                    <el-input v-model="ruleForm.equipment_location"></el-input>
                </el-form-item>
                <el-form-item label="器材状态" prop="equipment_status">
                    <el-radio-group v-model="ruleForm.equipment_status">
                        <el-radio label="正常"></el-radio>
                        <el-radio label="维修"></el-radio>
                        <el-radio label="损坏"></el-radio>
                        <el-radio label="其他"></el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="备注信息" prop="equipment_message">
                    <el-input v-model="ruleForm.equipment_message"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="submitForm('ruleForm')">添加</el-button>
                    <el-button @click="resetForm('ruleForm')">重置</el-button>
                </el-form-item>
            </el-form>
            <!-- <span slot="footer" class="dialog-footer">
                <el-button @click="dialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
            </span> -->
        </el-dialog>
    </div>
</template>

<script>
import request from '@/utils/request';
export default {
    data() {
        return {
            form: {
                equipmentName: null
            },
            dialogVisible: false,
            tableData: [],
            currentPage: 1,
            pageSize: 10,
            total: 0,
            ruleForm: {
                equipment_name: '',
                equipment_location: '',
                equipment_status: '正常',
                equipment_message: ''
            },
            rules: {
                equipment_name: [
                    { required: true, message: '请输器材名称', trigger: 'blur' }
                ],
                equipment_location: [
                    { required: true, message: '请输器材位置', trigger: 'blur' }
                ]
            }
        }
    },
    methods: {
        handleSizeChange(val) {
            this.pageSize = val
            this.getList()
        },
        handleCurrentChange(val) {
            this.currentPage = val
            this.getList()
        },
        handleClick(val) {
            this.getList()
        },
        handleClose(done) {
            this.$confirm('确认关闭？')
                .then(_ => {
                    done();
                })
                .catch(_ => { });
        },
        submitForm(formName) {
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    alert('submit!');
                } else {
                    console.log('error submit!!');
                    return false;
                }
            });
        },
        resetForm(formName) {
            this.$refs[formName].resetFields();
        },
        getList() {
            request({
                url: '/gym-admin/equipment/list',
                method: 'get',
                params: {
                    equipmentName: this.form.equipmentName,
                    pageNo: this.currentPage,
                    pageSize: this.pageSize
                }
            }).then(res => {
                const data = res.data
                this.tableData = data.records
                this.currentPage = data.current
                this.total = data.total
                console.log(res);
            })
        }
    },
    created() {
        this.getList()
    }
}
</script>

<style scoped lang='scss'>
.equipment-container {
    .header {
        .query {
            width: 300px;
            margin-right: 10px;
        }
    }

    .pagination {
        padding-top: 10px;
    }
}
</style>
